package scau.erps.view.system.teacher;	

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import scau.erps.app.Erps;
import scau.erps.entity.OrderSet;
import scau.erps.service.OrderSetService;
import scau.erps.service.impl.OrderSetServiceImpl;

/**
 * 订单参数编辑对话框
 * @author outsider
 * 
 */
public class OrderSetEditDialog extends JDialog implements ActionListener{
	private static final long serialVersionUID = 1L;
	private JTextField totalJtf,priceJtf;
	private String total,price;
	private JButton generateBtn;
	private OrderSet orderSet;
	public OrderSetEditDialog(OrderSet orderSet){
		this.orderSet=orderSet;
		this.total=Integer.toString(orderSet.getTotal());
		this.price=Double.toString(orderSet.getPrice());
		this.setTitle(orderSet.getYear()+" "+orderSet.getProduct()+" "+orderSet.getMarket()+" 订单参数设置");
		this.setSize(350,200);
		JPanel contentPanel = new JPanel();
		contentPanel.setLayout(new BorderLayout());		
		JLabel totalLabel = new JLabel("产品数:");
		totalJtf = new JTextField(4);
		totalJtf.setText(total);
		JLabel priceLabel = new JLabel("参考价:");
		priceJtf = new JTextField(4);	
		priceJtf.setText(price);
		JPanel panel2 = new JPanel();
		panel2.add(totalLabel);
		panel2.add(totalJtf);
		JPanel panel3 = new JPanel();
		panel3.add(priceLabel);
		panel3.add(priceJtf);		
		JPanel panel5 = new JPanel();
		generateBtn = new JButton("确认");
		generateBtn.addActionListener(this);		
		panel5.add(generateBtn);
		contentPanel.add(panel2,BorderLayout.NORTH);
		contentPanel.add(panel3,BorderLayout.CENTER);
		contentPanel.add(panel5,BorderLayout.SOUTH);
		this.setContentPane(contentPanel);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setModal(true);
		this.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==generateBtn) {				
			int total = Integer.parseInt(totalJtf.getText());
			double price = Double.parseDouble(priceJtf.getText());
			orderSet.setTotal(total);
			orderSet.setPrice(price);
			OrderSetService orderSetService=Erps.getIocInstance().get(OrderSetServiceImpl.class);
			orderSetService.updateOrderSet(orderSet);
			String message ="订单参数修改成功";
			JOptionPane.showMessageDialog(null, message);	
			dispose();
		}				
	}
}

